********************************************************************************
*** Voting for Populism in Europe Replication Files
*** Figure 3: Parliamentary Elections in Europe, 1970-2019
*** 
*** Required data files: "parties_votes/party_classifications.dta", "parties_votes/parlgov_election_05202020.csv"
*** 
*** Note: Need to add ccode ado file from http://www.columbia.edu/~rh2883/stats.html
*** Created by: Thomas Cunningham
*** Date: 22 December 2020
******************************************************************
clear all
version 16.1
cd ..

* Import New Party Classifications (Hand-coded)
use "data/parties_votes/party_classifications.dta", clear


drop if parlgov_dataset_party_id == . // not in ParlGov Data

drop if inlist(jointid, "E40", "P266", "M12", "M29") // duplicate parlgov ID numbers for successor party


keep cname ccode pname_partyfacts pname_eng parlgov_dataset_party_id right_pop left_pop all_extreme all_main main_left main_right inglehart_* mudde_rpop-rueda_mainr


tempfile parties
save `parties'



* ParlGov Election Data 
* Source: http://www.parlgov.org/data/table/view_election/ (Accessed 20 May 2020)
import delimited "data/parties_votes/parlgov_election_05202020.csv", clear


* Assign CCODES
ccode country_name,from(CTY) to(COW) gen(ccode)


* Subset to OECD 23 
gen oecd_23=0
	replace oecd_23 = 1 if inlist(ccode, 2, 20, 200, 205, 210, 211, 212, 220, 225, 230)
	replace oecd_23 = 1 if inlist(ccode, 235, 255, 305, 325, 350, 375, 380, 385, 390)
	replace oecd_23 = 1 if inlist(ccode, 395, 740, 900, 920)

keep if oecd_23==1
drop oecd_23


** Merge Party Classifications
rename party_id parlgov_dataset_party_id

merge m:1 parlgov_dataset_party_id using `parties', gen(merged)
drop cname

rename country_name cname
order cname ccode *

** Generate Election Year

generate date = date(election_date, "MDY")
	format date %td

gen year = year(date)
*gene date = date(election_date, "YMD")
*	format date %td
*gen year = year(date)


* Drop EU Parliamentary Elections
keep if election_type == "parliament"

order cname ccode year date * 

* Assign Seat Shares
gen seats_share = (seats/seats_total)*100

* Updating data with Norris GPS dataset classifications

replace main_left=1 if inlist(party_name, "Die Grünen  Die Grüne Alternative", "Agalev  Groen", "JETZT  Liste Pilz", "Alternativet")

replace main_left=1 if inlist(party_name, "Vihreä Liitto  Gröna Förbundet", "Bündnis 90 / Die Grünen", "Daonlathaigh Shóisialta", "Green Party   Comhaontas Glas", "GroenLinks", "Feministiskt initiativ", "Miljöpartiet de Gröna", "Green Party", "Scottish National Party"   )

replace main_right=1 if inlist(party_name, "NEOS  Das Neue Österreich", "Det Radikale Venstre", "Kristeligt Folkeparti", "Kristillisdemokraatit  Kristdemokraterna")

replace main_right=1 if inlist(party_name, "Ruotsalainen Kansanpuolue  Svenska Folkepartiet i Finland", "Union des démocrates et indépendants", "Associativo Italiani all'Estero",  "ChristenUnie", "Venstre"  )

replace right_pop=1 if inlist(party_name, "Nieuw-Vlaamse Alliantie", "Ny-Liberal Alliance", "Enosi Kentroon", "Renua Ireland", "Vox", "Kristdemokraterna", "Brexit Party")

replace left_pop=1 if inlist(party_name, "La France Insoumise", "Dlúthphartíocht  Pobal Roimh Bhrabús", "50PLUS", "Miljøpartiet De Grønne", "Senterpartiet", "Partido pelos Animais e pela Natureza", "Republican Left of Catalonia"  )

*** Sum Vote Totals for Each Party
foreach v of varlist all_extreme right_pop left_pop  all_main main_left main_right inglehart_lpop inglehart_rpop /*
*/ inglehart_pop inglehart_lmain inglehart_rmain inglehart_main mudde_rpop-rueda_mainr {
	replace `v' =  1 if `v' == -1 // roodujin_lpop, rovny_lpop, burgoon_lpop, algan_left, attewall, rooduijn_burgoon
	replace `v' =  1 if `v' == 5  // algan_eurosk
	replace `v' =  1 if `v' == 4 // algan_anti
	replace `v' =  1 if `v' == 3 // algan_pop, rodrik, vankessel_pop 
	
bysort ccode date: egen `v'_vs = total(cond(`v' == 1 ,vote_share, .)) 
bysort ccode date: egen `v'_seats = total(cond(`v' == 1 ,seats_share, .)) 

}

* Set non-European countries to missing for populist vote shares
foreach v of varlist  all_extreme right_pop left_pop inglehart_lpop inglehart_rpop /*
*/ inglehart_pop inglehart_lmain inglehart_rmain inglehart_main {
	replace `v'_vs = . if inlist(cname, "Japan", "Australia", "New Zealand", "Canada", "United States")
	replace `v'_seats = . if inlist(cname, "Japan", "Australia", "New Zealand", "Canada", "United States")
}

* Clean up and subset after 1960
keep cname ccode year date *_vs *_seats

keep if year >=1960
duplicates drop

** Instances of two elections in one year. Use second election.

duplicates tag cname year , gen(tag)

drop if cname == "United Kingdom" & date == date("28feb1974", "DMY")
drop if cname == "Ireland" & date == date("18feb1982", "DMY")
drop if cname == "Greece" & date == date("18jun1989", "DMY")
drop if cname == "Greece" & date == date("06may2012", "DMY")
drop if cname == "Greece" & date == date("25jan2015", "DMY")
list cname year date if tag!=0
       drop tag
	   
	   
la var year  "Election Year"
la var date  "Election Date"


	   
* Drop countries not used in analysis
drop if inlist(cname, "Japan", "Australia", "New Zealand", "Canada", "United States", "Switzerland", "Iceland", "Luxembourg")


unique cname

drop if year==2016 & cname=="Spain"

drop if year==2020

keep year right_pop_vs left_pop_vs main_left_vs main_right_vs

sort year


collapse (mean) *_vs, by(year)	

tsset year


local k=1960
gen tag=.
forval y=1960/2018{
	replace tag=`k' if year==`k'
	local k=`k'+4
}

replace tag=tag+3
replace tag=tag[_n-1] if tag==.

collapse(mean) *_vs, by(tag)

rename tag year


keep if year >=1970 & year <=2019
la var right_pop_vs "Populist Right"
la var left_pop_vs   "Populist Left"
la var main_left_vs   "Center Left"
la var main_right_vs   "Center Right"

twoway connected right_pop_vs year, msymbol(d)|| connected left_pop_vs year, lpattern(dash) msymbol(s) || connected main_left_vs year, lpattern(dash) msymbol(t) || /*
*/ connected main_right_vs year, msymbol(o)  ///
 scheme(s1color) ///
text(39 2007.9 "Financial Crisis", place(e) size(vsmall)) ///
xline(2008,lpattern(dash) lcolor(gray)) ///
xlab(1970(5)2020) ///
xtitle("") ///
ytitle("% Vote Share") ///
title("Parliamentary Elections in Europe, 1970-2019")  ///
subtitle("Vote Share by Party Family") ///
note("Source: ParlGov, 2020. 15 European countries.", size(vsmall))
graph export "output/figure3.pdf", replace 

